<template>
	<div class="app-container peoples_detail" v-loading="loading">
		<el-row :gutter="10" class="mb10">
			<el-col :span="1.5">
				<el-button type="warning" plain icon="el-icon-close" size="mini" @click="handleClose">关闭</el-button>
			</el-col>
			<right-toolbar :search="false" @queryTable="initPageRequest"></right-toolbar>
		</el-row>
		<el-descriptions :column="5" size="medium" border direction="vertical" title="基本信息">
			<el-descriptions-item label="姓名">{{ detail.name }}</el-descriptions-item>
			<el-descriptions-item label="性别">
				<dict-tag :options="dict.type.sys_user_sex" :value="detail.gender" />
			</el-descriptions-item>
			<el-descriptions-item label="手机号码">{{ detail.phoneNumber }}</el-descriptions-item>
			<el-descriptions-item label="用户邮箱">{{ detail.email }}</el-descriptions-item>
			<el-descriptions-item label="身份证号">{{ detail.idCard }}</el-descriptions-item>
			<el-descriptions-item label="年龄">{{ detail | ageFilter }}岁</el-descriptions-item>
			<el-descriptions-item label="最高学历">
				<dict-tag :options="dict.type.sp_highest_degree" :value="detail.highestDegree" />
			</el-descriptions-item>
			<el-descriptions-item label="身份类型">
				<dict-tag :options="dict.type.sp_people_type" :value="detail.identityType" />
			</el-descriptions-item>
			<el-descriptions-item label="职务">{{ detail.deptZw }}</el-descriptions-item>
			<el-descriptions-item label="职级">{{ detail.deptZj }}</el-descriptions-item>
			<el-descriptions-item label="职称">{{ detail.deptZc }}</el-descriptions-item>
			<el-descriptions-item label="备注">{{ detail.remark }}</el-descriptions-item>
		</el-descriptions>
		<el-descriptions :column="5" size="medium" border direction="vertical" title="人事信息">
			<el-descriptions-item label="人事号">{{ detail.userNum }}</el-descriptions-item>
			<el-descriptions-item label="用人形式">
				<dict-tag :options="dict.type.sp_user_type" :value="detail.userType" />
			</el-descriptions-item>
			<el-descriptions-item label="单位/部门">{{ detail.deptName }}</el-descriptions-item>
			<el-descriptions-item label="上岗时间">{{ detail.startDate }}</el-descriptions-item>
			<el-descriptions-item label="岗位名称">{{ detail.postName }}</el-descriptions-item>
			<el-descriptions-item label="岗位确定依据">
				<dict-tag :options="dict.type.sp_post_basis" :value="detail.postBasis" />
			</el-descriptions-item>
			<el-descriptions-item label="涉密等级">
				<dict-tag :options="dict.type.sp_level" :value="detail.spLevel" />
			</el-descriptions-item>
			<el-descriptions-item label="管理干部类型">
				<dict-tag :options="dict.type.sp_leader_type" :value="detail.managementType" />
			</el-descriptions-item>
			<el-descriptions-item label="事项">
				<dict-tag :options="dict.type.sp_project_type" :value="detail.engageInProject" />
			</el-descriptions-item>
			<el-descriptions-item label="是否到出入境登记备案">{{ detail.isClassFiling | switchFilter }}</el-descriptions-item>
			<el-descriptions-item label="是否统一保管出入境证件">{{ detail.isUnifiedCustody | switchFilter }}</el-descriptions-item>
			<el-descriptions-item label="是否统一保管出入境证件" v-if="detail.isUnifiedCustody">
				<dict-tag :options="dict.type.sp_certificate_type" :value="detail.certificateType" />
			</el-descriptions-item>
		</el-descriptions>
		<h2 class="table-title">等级变更记录</h2>
		<el-table :data="gradeList" style="width: 100%">
			<el-table-column label="序号" type="index" width="48" align="center" />
			<el-table-column label="姓名" prop="userName" min-width="100" />
			<el-table-column label="原保密等级" min-width="100">
				<template slot-scope="{ row }">
					<dict-tag :options="dict.type.sp_level" :value="row.sourceLevel" />
				</template>
			</el-table-column>
			<el-table-column label="目标保密等级" min-width="100">
				<template slot-scope="{ row }">
					<dict-tag :options="dict.type.sp_level" :value="row.targetLevel" />
				</template>
			</el-table-column>
			<el-table-column label="变更时间" min-width="100">
				<template slot-scope="scope">
					<span>{{ parseTime(scope.row.changeDate, '{y}-{m}-{d}') }}</span>
				</template>
			</el-table-column>
			<el-table-column label="变更理由" prop="des" min-width="360" />
			<el-table-column label="是否需要审批" align="center" min-width="100">
				<template slot-scope="{ row }">
					<dict-tag :options="dict.type.sys_yes_no" :value="row.isAudit" />
				</template>
			</el-table-column>
		</el-table>
		<h2 class="table-title">年度考核记录</h2>
		<el-table :data="examineList" style="width: 100%">
			<el-table-column label="序号" type="index" width="55" align="center" />
			<el-table-column label="姓名" prop="userName" min-width="160" />
			<el-table-column label="年份" align="center" prop="year" min-width="160" />
			<el-table-column label="考核等次" align="center" min-width="120">
				<template slot-scope="{ row }">
					<dict-tag :options="dict.type.sp_examine_level" :value="row.result" />
				</template>
			</el-table-column>
			<el-table-column label="是否校先进个人" align="center" min-width="120">
				<template slot-scope="{ row }">
					<dict-tag :options="dict.type.sys_yes_no" :value="row.isAdvanced" />
				</template>
			</el-table-column>
		</el-table>
		<h2 class="table-title">复审记录</h2>
		<el-table :data="reviewList" style="width: 100%">
			<el-table-column label="序号" type="index" width="55" align="center" />
			<el-table-column label="复审状态" align="center" prop="status" width="80">
				<template slot-scope="{ row }">
					<el-tag type="success" v-if="row.status === 'pass'">成功</el-tag>
					<el-tag type="danger" v-else-if="row.status === 'fail'">失败</el-tag>
					<el-tag v-else>待复审</el-tag>
				</template>
			</el-table-column>
			<el-table-column label="姓名" prop="userName" min-width="150" />
			<el-table-column label="涉密等级" align="center" prop="spLevel" min-width="100">
				<template slot-scope="{ row }">
					<dict-tag :options="dict.type.sp_level" :value="row.spLevel" />
				</template>
			</el-table-column>
			<el-table-column label="复审日期" align="center" prop="recheckDate" min-width="120">
				<template slot-scope="{ row }">
					<span>{{ parseTime(row.recheckDate, '{y}-{m}-{d}') }}</span>
				</template>
			</el-table-column>
		</el-table>
		<h2 class="table-title">追责记录</h2>
		<el-table :data="punishmentList" style="width: 100%">
			<el-table-column label="序号" type="index" width="48" align="center" />
			<el-table-column label="姓名" prop="userName" min-width="120" />
			<el-table-column label="追责日期" min-width="120">
				<template slot-scope="scope">
					<span>{{ parseTime(scope.row.punishmentDate, '{y}-{m}-{d}') }}</span>
				</template>
			</el-table-column>
			<el-table-column label="追责说明" prop="des" min-width="240" />
		</el-table>
		<h2 class="table-title">因私出国记录</h2>
		<el-table :data="leaveList" style="width: 100%">
			<el-table-column label="序号" type="index" width="48" align="center" />
			<el-table-column label="姓名" prop="userName" min-width="120" />
			<el-table-column label="审批日期" prop="auditDate" min-width="120">
				<template slot-scope="scope">
					<span>{{ parseTime(scope.row.auditDate, '{y}-{m}-{d}') }}</span>
				</template>
			</el-table-column>
			<el-table-column label="开始日期" prop="startDate" min-width="120">
				<template slot-scope="scope">
					<span>{{ parseTime(scope.row.startDate, '{y}-{m}-{d}') }}</span>
				</template>
			</el-table-column>
			<el-table-column label="截止日期" prop="endDate" min-width="120">
				<template slot-scope="scope">
					<span>{{ parseTime(scope.row.endDate, '{y}-{m}-{d}') }}</span>
				</template>
			</el-table-column>
			<el-table-column label="地点" prop="targetAddress" min-width="120" />
			<el-table-column label="说明" prop="des" min-width="250" />
		</el-table>
		<h2 class="table-title">月度补贴记录</h2>
		<el-table :data="subsidyList" style="width: 100%">
			<el-table-column label="序号" type="index" width="48" align="center" />
			<el-table-column label="姓名" prop="userName" min-width="150" />
			<el-table-column label="补贴年" align="center" prop="year" min-width="150" />
			<el-table-column label="补贴月" align="center" prop="month" min-width="150" />
			<el-table-column label="涉密等级" align="center" min-width="150">
				<template slot-scope="{ row }">
					<dict-tag :options="dict.type.sp_level" :value="row.spLevel" />
				</template>
			</el-table-column>
			<el-table-column label="补贴金额" align="center" prop="money" min-width="150" />
		</el-table>
		<h2 class="table-title">脱密记录</h2>
		<el-table :data="ciphertextList" style="width: 100%">
			<el-table-column label="序号" type="index" width="48" align="center" />
			<el-table-column label="姓名" prop="userName" min-width="150" />
			<el-table-column label="涉密等级" align="center" prop="spLevel" min-width="100">
				<template slot-scope="{ row }">
					<dict-tag :options="dict.type.sp_level" :value="row.spLevel" />
				</template>
			</el-table-column>
			<el-table-column label="是否委托管理" align="center" prop="isEntrustedManagement" min-width="100">
				<template slot-scope="{ row }">
					<template v-if="row.isEntrustedManagement === 'Y'">是</template>
					<template v-if="row.isEntrustedManagement === 'N'">否</template>
				</template>
			</el-table-column>
			<el-table-column label="去向单位" prop="destinationDept" min-width="200" />
			<el-table-column label="脱密开始日期" align="center" prop="startDate" min-width="120">
				<template slot-scope="{ row }">
					<span>{{ parseTime(row.startDate, '{y}-{m}-{d}') }}</span>
				</template>
			</el-table-column>
			<el-table-column label="脱密结束日期" align="center" prop="endDate" min-width="120">
				<template slot-scope="{ row }">
					<span>{{ parseTime(row.endDate, '{y}-{m}-{d}') }}</span>
				</template>
			</el-table-column>
		</el-table>
		<h2 class="table-title">责任书</h2>
		<el-table :data="dutybookList" style="width: 100%">
			<el-table-column label="序号" type="index" width="48" align="center" />
			<el-table-column label="保密人员" prop="userId" min-width="100" />
			<el-table-column label="文件名称" prop="fileName" min-width="150" show-overflow-tooltip />
			<el-table-column label="文件类型" prop="fileType" min-width="100" />
			<el-table-column label="文件大小" prop="fileSize" min-width="100" />
			<el-table-column label="文件后缀" prop="fileFileSuffix" min-width="100" />
			<el-table-column label="文件地址" prop="fileUrl" min-width="360" show-overflow-tooltip />
		</el-table>
	</div>
</template>

<script>
import moment from 'moment';
import { listDuty } from '@/api/personnal/duty';
import { getUser } from '@/api/personnal/person';
import { listLevel } from '@/api/personnal/grade';
import { listLeave } from '@/api/personnal/leave';
import { listYear } from '@/api/personnal/examine';
import { listMoney } from '@/api/personnal/subsidy';
import { listOut } from '@/api/personnal/ciphertext';
import { listRecheck } from '@/api/personnal/recheck';
import { listPunishment } from '@/api/personnal/punishment';
export default {
	dicts: [
		'sys_yes_no',
		'sys_user_sex',
		'sp_highest_degree',
		'sp_people_type',
		'sp_user_type',
		'sp_post_basis',
		'sp_level',
		'sp_leader_type',
		'sp_project_type',
		'sp_examine_level',
		'sp_certificate_type'
	],
	data() {
		return {
			detail: {},
			gradeList: [],
			leaveList: [],
			loading: false,
			reviewList: [],
			examineList: [],
			subsidyList: [],
			dutybookList: [],
			ciphertextList: [],
			punishmentList: []
		};
	},
	filters: {
		ageFilter(data) {
			if (!!data.idCard) {
				let birthDate = moment(data.idCard.substring(6, 14), 'YYYYMMDD');
				return moment().diff(birthDate, 'years');
			}
		},
		switchFilter(val) {
			if (val === '1') {
				return '是';
			} else if (val === '2') {
				return '否';
			}
		}
	},
	computed: {
		userId() {
			return this.$route.params.id || '';
		},
		queryParams() {
			return { pageNum: 1, pageSize: 99999, userId: this.userId };
		}
	},
	watch: {
		userId: {
			handler() {
				this.initPageRequest();
			},
			immediate: true
		}
	},
	methods: {
		//初始化页面请求
		async initPageRequest() {
			this.loading = true;
			await this.getPeoplesDetail();
			await this.getGradeListData();
			await this.getYearCheckData();
			await this.getLeaveListData();
			await this.getCiphertextList();
			await this.getPunishmentData();
			await this.getRecheckListData();
			await this.getSubsidyListData();
			await this.getDutybookData();
			this.loading = false;
		},

		//获取涉密人员详情
		async getPeoplesDetail() {
			let result = await getUser(this.userId);
			if (result.code === 200) {
				let datas = result.data || {};
				this.detail = result.data || {};
			}
		},

		//获取等级变更列表
		async getGradeListData() {
			let result = await listLevel(this.queryParams);
			if (result.code === 200) {
				this.gradeList = result.rows || [];
			}
		},

		//获取年度考核记录
		async getYearCheckData() {
			let result = await listYear(this.queryParams);
			if (result.code === 200) {
				this.examineList = result.rows || [];
			}
		},

		//获取复核记录
		async getRecheckListData() {
			let result = await listRecheck(this.queryParams);
			if (result.code === 200) {
				this.reviewList = result.rows || [];
			}
		},

		//获取追责记录
		async getPunishmentData() {
			let result = await listPunishment(this.queryParams);
			if (result.code === 200) {
				this.punishmentList = result.rows || [];
			}
		},

		//获取因私出国记录
		async getLeaveListData() {
			let result = await listLeave(this.queryParams);
			if (result.code === 200) {
				this.leaveList = result.rows || [];
			}
		},

		//获取月度补贴记录
		async getSubsidyListData() {
			let result = await listMoney(this.queryParams);
			if (result.code === 200) {
				this.subsidyList = result.rows || [];
			}
		},

		//获取脱密记录
		async getCiphertextList() {
			let result = await listOut(this.queryParams);
			if (result.code === 200) {
				this.ciphertextList = result.rows || [];
			}
		},

		//获取责任书数据
		async getDutybookData() {
			let result = await listDuty(this.queryParams);
			if (result.code === 200) {
				this.dutybookList = result.rows || [];
			}
		},

		/** 返回按钮操作 */
		handleClose() {
			this.$router.back();
			this.$tab.closePage();
		}
	}
};
</script>

<style lang="scss" scoped>
.peoples_detail::v-deep {
	height: calc(100vh - 84px);
	overflow: auto;
	.el-descriptions {
		margin-top: 20px;
	}
	.el-descriptions__header {
		margin-bottom: 10px;
	}
	.el-descriptions-item__label {
		width: 100px;
	}
	h2.table-title {
		color: #303133;
		font-size: 16px;
		line-height: 21px;
		font-weight: bold;
		margin: 20px 0 10px;
	}
	.el-table {
		border: solid 1px #e6ebf5;
		border-bottom: none;
	}
}
</style>
